import json

import requests


class IRHMApi:

    # 封装登录接口
    @classmethod
    def ihrm_login_api(cls, login_body):
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 添加员工接口
    @classmethod
    def add_mep(cls, token, add_emp_body):
        add_emp_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_emp_header = {"Content-Type": "application/json", "Authorization": token}

        add_emp_resp = requests.post(url=add_emp_url, headers=add_emp_header, json=add_emp_body)
        return add_emp_resp

    # 查询员工接口
    @classmethod
    def query_emp(cls, emp_id, token):
        query_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        query_emp_header = {"Authorization": token}
        query_emp_resp = requests.get(url=query_emp_url, headers=query_emp_header)
        return query_emp_resp

    # 修改员工接口
    @classmethod
    def modify_emp(cls, emp_id, token, modify_emp_body):
        modify_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        modify_emp_header = {"Content-Type": "application/json",
                             "Authorization": token}

        modify_emp_resp = requests.put(url=modify_emp_url, headers=modify_emp_header, json=modify_emp_body)
        return modify_emp_resp

    # 删除员工接口
    @classmethod
    def delete_emp(cls, emp_id, token):
        delete_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        delete_emp_header = {"Authorization": token}
        delete_emp_resp = requests.delete(url=delete_emp_url, headers=delete_emp_header)
        return delete_emp_resp


if __name__ == '__main__':
    token = "f76b900b-c97f-4248-b64d-b6358542f992"
    body = {
        "username": "小猪佩奇",
        "mobile": "15988765238",
        "workNumber": "22"
    }

    resp = IRHMApi.add_mep(token, body)
    print("resp=",resp.json())
    # id='1573883846087159808'
    # token="f76b900b-c97f-4248-b64d-b6358542f992"
    # resp=IRHMApi.delete_emp()